<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>React06</title>
  <style>
    button {
      margin-inline: 10px;
    }
  </style>

</head>

<body>
  <div class="container"></div>
  <!-- react核心库 -->
  <script src="./js/react.development.js"></script>
  <!-- react拓展库 用于支持react操作dom -->
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/prop-types.js"></script>
  <script src="./js/babel.min.js"></script>

  <script type="text/babel">
    // 非受控组件 ===> 现用现取
    class Login extends React.Component {
      render() {
        return (
          <form action="" onSubmit={this.handleSubmit}>
            用户名: <input type="text" name="username" ref={c => this.usernameRef = c}/>  
            密码: <input type="password" name="password" ref={c => this.passwordRef = c}/>
            <button>登录</button>
          </form>
        )
      }

      handleSubmit = (event) => {
        event.preventDefault()
        const { usernameRef, passwordRef } = this
        alert(`用户名: ${usernameRef.value}, 密码: ${passwordRef.value}`)
      }
    }

    ReactDOM.render(<Login/>, document.querySelector('.container'))
  </script>
</body>

</html>